package com.zy.test.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.sun.tools.javac.jvm.Code;

import java.util.Collections;
//代码生成工具
public class CodeGenerator {
    public static void main(String[] args) {
        CodeGeneratorMethod();

    }

    private static void CodeGeneratorMethod(){
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/qing?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true", "root", "password")
                .globalConfig(builder -> {
                    builder.author("jhr") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("/Users/jhr/Library/Mobile Documents/com~apple~CloudDocs/前后端分离项目实战/springboot-graduation-mp/src/main/java/"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("cn.ahnu") // 设置父包名
                            .moduleName("") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "/Users/jhr/Library/Mobile Documents/com~apple~CloudDocs/前后端分离项目实战/springboot-graduation-mp/src/main/resources/mapper/")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("sys_user") // 设置需要生成的表名
                            .addTablePrefix("t_", "sys_"); // 设置过滤表前缀
                })
//                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
